package com.egu.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.Customer;
import com.egu.service.CustomerService;
import com.egu.vo.CustomerVo;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("customer")
public class CustomerController {

	@Autowired
	private CustomerService customerService;

	@RequestMapping("listUI")
	public String listUI() {
		return "customer/listUI";
	}

	// rder = "asc" offset = 0 limit = 10;
	/*
	 * @RequestMapping("/getList")
	 * 
	 * @ResponseBody public RequestPageVo<Customer> getList(
	 * 
	 * @ModelAttribute(value = "param") PageParam param ,Customer customer) {
	 * RequestPageVo<Customer> vo = customerService.getList(param,customer); return
	 * vo; }
	 */
	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<CustomerVo> getList(@ModelAttribute(value = "param") PageParam param, CustomerVo customerVo) {
		RequestPageVo<CustomerVo> vo = customerService.getVoList(param, customerVo);
		return vo;
	}

	
	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<Customer> saveOrUpdate(Customer customer) {
		RequestResultVo<Customer> result = new RequestResultVo<Customer>();
		if (customer != null) {
			return customerService.saveOrUpdate(customer);
		} else {
			result.setSuccess(false);
		}
		return result;
	}

	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<Customer> deleteDataById(@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<Customer> result = new RequestResultVo<Customer>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("传入id为空");
			return result;
		}
		result = customerService.deleteDataById(id);
		return result;
	}
	
	@RequestMapping("/getDataByCurrentUser")
	public @ResponseBody RequestResultVo<List<Customer>> getDataByCurrentUser() {
		RequestResultVo<List<Customer>> result = new RequestResultVo<List<Customer>>();
		result = customerService.getDataByCurrentUser();
		return result;
	}
}
